package com.hf.dao;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.hf.entity.User;
import com.hf.utils.DBUtils;

public class UserInfoDao {
	
	public void modify(User user){
		
		String sql = "update buer_user set user_name=?,user_sex=?,user_birthday=?,user_pic=?,user_address=? where user_id=?";
		Connection conn =null;
		ResultSet rs =null;
		PreparedStatement ps = null;
		try{
			conn = DBUtils.getConnection();
			ps = conn.prepareStatement(sql);
			ps.setString(1, user.getUser_name());
			ps.setString(2, user.getUser_sex());
			ps.setDate(3,  new java.sql.Date(user.getUser_birthday().getTime()));
			ps.setString(4, user.getUser_pic());
			ps.setString(5, user.getUser_address());
			ps.setInt(6, user.getUser_id());
			ps.executeUpdate();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			DBUtils.close(conn, rs, null, ps);
		}
	}
	
	public User queryid(int user_id){
		User user = new User();
		String sql = "select * from buer_user where user_id=?";
		Connection conn =null;
		ResultSet rs =null;
		PreparedStatement ps = null;
		try{
			conn = DBUtils.getConnection();
			ps = conn.prepareStatement(sql);
			ps.setInt(1, user_id);
			rs = ps.executeQuery();
			if(rs.next()){
				user.setUser_id(rs.getInt(1));
				user.setUser_login(rs.getString(2));
				user.setUser_password(rs.getString(3));
				user.setUser_name(rs.getString(4));
				user.setUser_sex(rs.getString(5));
				user.setUser_birthday(rs.getDate(6));
				user.setUser_address(rs.getString(7));
				user.setUser_industry(rs.getString(8));
				user.setUser_pic(rs.getString(9));
				user.setUser_email(rs.getString(10));
				user.setUser_QQ(rs.getString(11));
				user.setUser_WeChat(rs.getString(12));
				user.setUser_xinlang(rs.getString(13));
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			DBUtils.close(conn, rs, null, ps);
		}
		return user;
	}
	
}
